package com.test.rabforspringboot.controller;

import com.test.rabforspringboot.provider.InitMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class IndexController {

    @Autowired
    private InitMessage initMessage;
    @Autowired
    private RabbitTemplate template;

    @RequestMapping("/send")
    public String sendMsg(){
        initMessage.sendMsg();
        return "success";
    }
    @RequestMapping("/sendToDirect")
    public String sendMsgToDirect(String routinKey,String str){
        template.convertAndSend("directExchange",routinKey,str);
        return "success";
    }
    @RequestMapping("/sendToTopic")
    public String sendMsgToTopic(String routingKey,String str){
        template.convertAndSend("topicExchange",routingKey,str);
        return "success";
    }

    @RequestMapping("/sendFanout")
    public String sendToFanout(){
            template.convertAndSend("fanoutExchange","",createData());
        return "success";
    }

    @RequestMapping("/sendDeadMsg")
    public String sendToDead(){
        System.out.println(System.currentTimeMillis());
        template.convertAndSend("deadExchange","deadRouting","哈喽");
        return "success";
    }




    private Map<String,Object> createData(){
        Map<String,Object> map=new HashMap<>();
        map.put("code",200);
        map.put("currentTime",System.currentTimeMillis());
        return map;
    }
}
